package com.jason.system.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jason.system.common.util.Pager;
import com.jason.system.entity.Number;
import com.jason.system.entity.Order;
import com.jason.system.mapper.OrderMapper;
import com.jason.system.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author jie
 * @version 1.0
 * success come from self-discipline
 * @date 2021/3/26 20:03
 */
@Slf4j
@Service
public class OrderServiceImpl implements OrderService {


  @Resource
  OrderMapper orderMapper;

  @Override
  public Pager<Order> getAllOrderS(Integer page, Integer size) {
    PageHelper.startPage(page,size);
    List<Order> orders = orderMapper.getAllOrderS();
    log.info("orders:{}",orders);
    PageInfo<Order> orderPageInfo = new PageInfo<>(orders);
    log.info("oderPageInfo:{}",orderPageInfo);
    return new Pager<>(orderPageInfo);
  }

  @Override
  public List<Order> getAllOrderNotFinish() {
    return orderMapper.getAllOrderNotFinish();
  }

  @Override
  public Pager<Order> searchOrders(Integer page, Integer size, String address, String stuName) {
    PageHelper.startPage(page,size);
    List<Order> orders = orderMapper.getSearchOrders(address,stuName);
    PageInfo<Order> orderPageInfo = new PageInfo<>(orders);
    return new Pager<>(orderPageInfo);
  }

  @Override
  public void insertOrder(Order order) {
    orderMapper.insertOrder(order);
  }

  @Override
  public void updateOrder(Order order) {
    orderMapper.updateOrder(order);
  }

  @Override
  public void updateOrderStatus(Integer oId, Integer status) {
    orderMapper.updateOrderStatus(oId,status);
  }

  @Override
  public boolean deleteOrder(Integer oId) {
    if (oId==null){
      return false;
    }else {
      orderMapper.deleteOrder(oId);
      return true;
    }
  }

  @Override
  public boolean deleteOrders(List<Integer> oIds) {
    if (oIds==null){
      return false;
    }else {
      orderMapper.deleteOrders(oIds);
      return true;
    }
  }
}
